package com.example.backend.mapper;

import com.example.backend.entity.Book;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface BookMapper {

    //显示所有书籍
    @Select("select * from books")
    List<Book> getAllBooks();

    //增加书籍
    @Insert("insert into books (bookId,bookName,author,num) values(#{bookId},#{bookName},#{author},#{num})")
    int addBooks(@Param("bookId") int id,@Param("bookName") String name,@Param("author") String author,@Param("num") int num);

    //查找书籍
    @Select("select * books where bookName = #{bookName}")
    List<Book> getBooks(@Param("bookName") String bookName);

    //删除书籍
    @Delete("delete from books where bookName = #{bookName}")
    int deleteBooks(@Param("bookName") String bookName);

    //修改书籍
    @Update("update books set bookName = #{bookName},author = #{author},num = #{num} where bookId = #{bookId}")
    int updateBooks(@Param("bookId") int id,@Param("bookName") String name,@Param("author") String author,@Param("num") int num);
}
